package common;

import java.io.Serializable;
import java.net.Inet4Address;
/**
 * Class represents the network location of a specific file. <br>
 * As a location we mean a pair (Inet4Address, port). <br>
 * This kind of simplification is completely sufficient for our needs. <br>
 * It implements basic methods used frequently in the rest of the code.<br>
 * Class implements interface Serializable for it is often a return object of return method. 
 */

public class NetLocation implements Serializable {
	/**
	 * The serial version unique identifier (SUID) of a class is a 64-bit hashcode computed from all the
	 * class's properties: its classname, the names of all interfaces which it implements, and the names
	 * and signatures of its member functions and fields. The SUID is identical for all versions of a class
	 * which are compatible under serialization.
	 * The serial version unique identifier (SUID) of a class is a 64-bit hashcode computed from all the
	 * class's properties: its classname, the names of all interfaces which it implements, and the names
	 * and signatures of its member functions and fields. The SUID is identical for all versions of a class
	 * which are compatible under serialization.
	 */
	private static final long serialVersionUID = -7027768322886184551L;
	
	
	/**
	 * Address specific to a network location.
	 */
	public final Inet4Address address;
	/**
	 * Port specific to a network location.
	 */
	public final int port;
	
	/**
	 * Method used to compare two network location
	 * @param location2 Location compared to.
	 * @return <code>true </code> if locations are the same <code>false </code> otherwise.
	 */
	public boolean isEqual(NetLocation location2){
		if(this.address.equals(location2.address))
			return true;
		return false;
	}
	/**
	 * Basic class constructor.
	 * @param address Address specific to a network location.
	 * @param port Port specific to a network location.
	 */
	public NetLocation(Inet4Address address, int port) {
		this.address = address;
		this.port = port;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return address + ":" + port;
	}
}
